//
//  YZFriendListCell2.m
//  VET
//
//  Created by lixiaoyi on 2018/7/12.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZFriendListCell2.h"
#import "UIView+YZBadge.h"
#import "UIImageView+WebCache.h"

@implementation YZFriendListCell2

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createView];
        [self layoutViews];
        
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }

    return self;
}

#pragma mark - createView
- (void)createView {
    [self.contentView addSubview:self.newFriend];
    [self.contentView addSubview:self.friendL];
    [self.contentView addSubview:self.lastNewFriend];
}

- (UIImageView *)newFriend{
    if (!_newFriend) {
        _newFriend = [UIImageView new];
        [_newFriend setImage:[UIImage imageNamed:@"face_friend"]];
    }
    
    return _newFriend;
}

- (UILabel *)friendL {
    if (!_friendL) {
        _friendL = [UILabel new];
        [_friendL setText:@"新的朋友"];
        [_friendL setTextColor:[UIColor blackColor]];
        [_friendL setFont:[UIFont systemFontOfSize:15]];
        [_friendL setTextAlignment:NSTextAlignmentLeft];
    }
    
    return _friendL;
}

- (UIImageView *)lastNewFriend {
    if (!_lastNewFriend) {
        _lastNewFriend = [UIImageView new];
        _lastNewFriend.frame = CGRectMake(0, 0, 28, 28);
    }
    
    return _lastNewFriend;
}

- (void)layoutViews {
    UIView *superView = self.contentView;
    [self.newFriend mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(superView.mas_left).with.offset(10);
        make.right.mas_equalTo(self.friendL.mas_left).with.offset(-10);
        make.centerY.mas_equalTo(superView);
        make.width.height.mas_equalTo(38);
    }];
    
    [self.friendL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.newFriend.mas_right).with.offset(10);
        make.centerY.mas_equalTo(superView);
        make.width.mas_equalTo(100);
    }];

    [self.lastNewFriend mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(superView.mas_right).with.offset(0);
        make.centerY.mas_equalTo(superView);
        make.width.height.mas_equalTo(26);
    }];
}

#pragma mark - setter
- (void)setModel:(YZFriendModel *)model {
    _model = model;
    NSString *icon = model.iconName;
    [self.lastNewFriend sd_setImageWithURL:[NSURL URLWithString:icon] placeholderImage:nil];
    if (model.showRedDot) {
        [self.newFriend setBadge:^(BadgeBuilder *builder) {
            builder.number = @0;
        }];
    }
}

- (void)hideRedHot {
    [self.newFriend setBadge:^(BadgeBuilder *builder) {
        
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
